//我是兔子，我修改了lingyi的代码  245345456
import java.util.Random;
import java.util.Scanner;

public class mima {
    public static void main(String[] args) {
        System.out.println(
                "------------欢迎使用密码管理系统------------\n 1、加密\n 2、解密 \n 3、判断密码强度\n 4、生成密码\n 5、退出\n----------------------------------------");
        Scanner s1 = new Scanner(System.in);
        for (;;) {
            System.out.println("选择你想要做的操作：");
            int num = s1.nextInt();
            if (num == 1) {
                System.out.println("输入你要加密的密码：");
                String str = s1.next();
                jiami(str);
            }
            if (num == 2) {
                System.out.println("输入你要解密的密码：");
                String str1 = s1.next();
                jiemi(str1);
            }
            if (num == 3) {
                System.out.println("输入要判断密码强度的密码：");
                String str2 = s1.next();
                panduan(str2);
            }
            if (num == 4) {
                System.out.println("输入要生成密码的位数：");
                int n1 = s1.nextInt();
                scmm(n1);
            }
            if (num == 5) {
                System.out.println("退出！");
                break;
            }
        }
    }

    public static Object jiami(String str) {
        StringBuffer buffer = new StringBuffer(str);
        for (int i = 0; i < str.length(); i++) {
            buffer.setCharAt(i, (char) (str.charAt(i) + 4 + i));
        }
        String str2 = "";
        str2 += buffer.charAt(buffer.length() - 1);
        for (int i = 1; i < buffer.length() - 1; i++) {
            str2 += buffer.charAt(i);
        }
        str2 += buffer.charAt(0);
        String str3 = "";
        for (int i = str2.length() - 1; i >= 0; i--) {
            str3 += str2.charAt(i);
        }
        System.out.println(str3);
        return str3;
    }

    public static Object jiemi(String str) {
        String str_1 = "";
        String str_2 = "";
        for (int i = str.length() - 1; i >= 0; i--) {
            str_1 += str.charAt(i);
        }
        str_2 += str_1.charAt(str_1.length() - 1);
        for (int i = 1; i < str_1.length() - 1; i++) {
            str_2 += str_1.charAt(i);
        }
        str_2 += str_1.charAt(0);
        StringBuffer buffer2 = new StringBuffer(str_2);
        for (int i = 0; i < str.length(); i++) {
            buffer2.setCharAt(i, (char) (str_2.charAt(i) - 4 - i));
        }
        System.out.println(buffer2);
        return buffer2;
    }

    public static Object panduan(String str) {
        for (int i = 0; i < str.length(); i++) {
            if (str.length() < 8 || (str.length() > 8 && str.matches("[0-9]+"))
                    || (str.length() > 8 && str.matches("[a-zA-Z]+"))) {
                System.out.println("密码强度弱");
                break;
            }
            if (str.length() > 8 && str.matches(".*\\d.*") && str.matches(".*[A-Z].*") && str.matches(".*[a-z].*")) {// str.matches(=.*[A-Z].*)
                System.out.println("密码强度强");
                break;
            }
            if ((str.length() > 8 && str.matches(".*\\d.*") && str.matches(".*[a-z].*"))
                    || (str.length() > 8 && str.matches(".*\\d.*") && str.matches(".*[A-Z].*"))) {
                System.out.println("密码强度中");
                break;
            }
        }
        return 0;
    }

    public static Object scmm(int length) {
        String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
        Random random = new Random();
        int rand = random.nextInt(9) + 1;
        StringBuilder password = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int randomIndex = random.nextInt(CHARACTERS.length());
            char randomCharacter = CHARACTERS.charAt(randomIndex);
            password.append(randomCharacter);
        }
        System.out.println(password);
        return password.toString();
    }
}
